use std::time::Duration;
use sea_orm::{ConnectOptions, DatabaseConnection};
use crate::dbclient::db_config::MysqlConfig;

pub async fn establish_connection(_conn : MysqlConfig) -> DatabaseConnection {
    let conn:String = format!("mysql://{}:{}@{}:{}/{}", _conn.user, _conn.password, _conn.host, _conn.port, _conn.dbname);
    println!("{}", conn);
    let mut opt = ConnectOptions::new(conn);
    opt.max_connections(100)
        .min_connections(5)
        .connect_timeout(Duration::from_secs(8))
        .acquire_timeout(Duration::from_secs(8))
        .idle_timeout(Duration::from_secs(8))
        .max_lifetime(Duration::from_secs(8))
        .sqlx_logging(true)
        .sqlx_logging_level(log::LevelFilter::Info);
        //.set_schema_search_path("my_schema"); // Setting default Pos

    let db = sea_orm::Database::connect(opt).await.expect("Failed to connect to database");
    db
}